<?php
require_once("materiel.php");
require_once("reservation.php");
require_once("adherant.php");
require_once("database.php");
// Fichier de controle des actions demandée au site
// Se comporte comme un dispatcher qui appellera les comportement selon les actions envoyer en url
// Les appel de methode doivent recevoir les données en $_POST ou $_GET

if(isset($_GET['action'])) 
{
	switch($_GET['action']) {
		case "addMaterielSport":
			$materiel = new Materiel();
			$sql = Database::getInstance();
			$materiel->addMaterielSport($_GET["designation"], $_GET["numAssoc"]); // designation stock id_categ
			break;

		case "updateMaterielSport":
			$materiel = new Materiel();
			$materiel->updateMaterielSport($_GET["id"], $_GET["designation"]);
			break;

		case "deleteMaterielSport":
			$materiel = new Materiel();
			$materiel->deleteMaterielSport($_GET["id"]);
			break;

		case "getMaterielSport":
			$materiel = new Materiel();
			$materiel->getInfoMaterielSport($_GET["id"]);
			break;

		case "addMateriel" : 
			$materiel = new Materiel();
			$materiel->addMateriel($_GET["description_materiel"], $_GET["reference"], $_GET["taille_lot"], $_GET["etat"], $_GET["categorie"]);
			break;

		case "getListe":
			//$sql = Database::getInstance();
			$materiel = new Materiel();
			$materiel->getListe($_GET["id"], $_GET["idAssoc"]);
			break;

		case "updateStock":
			$materiel = new Materiel();
			$materiel->updateStock(26, 3);
			break;

		case "connect":
			$adherent = new Adherant();
			$adherent->makeConnection($_GET["login"], $_GET["password"]);
			break;

		case "getLotDispo" : 
			$sql = database::getInstance();
			$sql->getMaterielStockByDay($_GET["idMaterielSport"],$_GET["idMateriel"],$sql->getIdAssoc($_COOKIE["m2l"])->numero_association,$_GET["date"]);
			break;

		case "addReservation" : 
			$reservation = new Reservation();
			$reservation->addReservation($_GET["date"], $_COOKIE["m2l"], $_GET["idMateriel"], $_GET["tailleLot"]);
			break;

		case "findReservation" : 
			$date = new DateTime(date("Y-m-d"));
			$reservation = new Reservation();
			$reservation->findReservation($_COOKIE["m2l"], $date->format("Y-m-d"), $_GET["nom"]);
			break;

		case "infoReservation" : 
			$reservation = new Reservation();
			$reservation->infoReservation($_GET["id"]);
			break;

		case "getReservation" : 
			$reservation = new Reservation();
			$reservation->infoReservation($_GET["idReservation"]);
			break;

		case "updateReservation" : 
			$reservation = new Reservation();
			$reservation->updateReservation($_GET["date"], $_COOKIE["m2l"], $_GET["idMateriel"], $_GET["tailleLot"], $_GET["idReservation"]);
			break;
	}
}

?>